package com.lm.activiti.boot.datatype;

import com.google.common.collect.HashMultiset;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Multiset;
import org.junit.Test;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author lm_jcf
 * @date 2019/12/26 10:31
 */
public class MultisetTest {

    @Test
    public void multiset() {

        // 可重复的set 集合，可适用于计数
        Multiset<String> multiset = HashMultiset.create();

        multiset.add("intoNum");
        multiset.add("intoNum");
        multiset.add("intoNum");

        System.out.println(multiset.count("intoNum"));
        System.out.println(multiset.size());

        multiset.setCount("intoNum", 3,6);
        System.out.println(multiset.count("intoNum"));

        /* Map               Corresponding Multiset   Supports null elements
        　　HashMap           HashMultiset                    Yes
        　　TreeMap           TreeMultiset                    Yes (if the comparator does)
        　　LinkedHashMap     LinkedHashMultiset              Yes
        　　ConcurrentHashMap ConcurrentHashMultiset          No
        　　ImmutableMap      ImmutableMultiset               No*/
    }
}
